﻿#include "communicationpage.h"
#include "ui_communicationpage.h"

CommunicationPage::CommunicationPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CommunicationPage),
    lastTime(0)
{
    ui->setupUi(this);
    scrollBar=ui->info_SA->verticalScrollBar();
    connect(scrollBar,&QScrollBar::rangeChanged,[this](int min, int max){
        scrollBar->setValue(max);
    });
}

CommunicationPage::~CommunicationPage()
{
    delete ui;
}

void CommunicationPage::setItem(QWidget* cItem){
    this->cItem=cItem;
}

QWidget* CommunicationPage::getItem(){
    return this->cItem;
}
void CommunicationPage::appendInfoItem(QWidget* infoItem){
    QVBoxLayout* infoPage=(QVBoxLayout*)ui->info_WT->layout();
    infoPage->insertWidget(infoPage->count()-1,infoItem);
}
void CommunicationPage::insertInfoItem(QWidget* infoItem){
    BaseInfo* baseInfo=qobject_cast<BaseInfo*>(infoItem);
    QVBoxLayout* infoPage=(QVBoxLayout*)ui->info_WT->layout();
    for(int i=infoPage->count()-1;i>-1;i--)
    {
        BaseInfo* item=qobject_cast<BaseInfo*> (infoPage->itemAt(i)->widget());
        if(item){
            if(baseInfo->getCreateTime()>item->getCreateTime()){
                infoPage->insertWidget(i+1,baseInfo);
                break;
            }
        }
    }
}
void CommunicationPage::setLastTime(const qint64 &lastTime){
    if(lastTime>this->lastTime)
        this->lastTime=lastTime;
}
qint64 CommunicationPage::getLastTime(){
    return lastTime;
}
